﻿using UnityEngine;

namespace TC
{
    public class Result_blueprint : TranslateBlueprint
    {
        public override editor.cfg.blueprint.Node OnTranslate(Node node)
        {
            Result t = node as Result;
            editor.cfg.blueprint.Result re = new editor.cfg.blueprint.Result();
            re.id = t.id;
            Port p = t.graph.GetConnect(t.flowIn);
            if(p != null)
            {
                re.nextNode = p.parent.id;
            }
            foreach (var i in t.inputPorts)
            {
                p = t.graph.GetConnect(i.Value);
                if(p == null)
                {
                    if (i.Value is ValueInput<int>)
                    {
                        re.results.Add(i.Key, new editor.cfg.blueprint.ConstInt() { value = (i.Value as ValueInput<int>).defaultValue });
                    }
                    else if (i.Value is ValueInput<float>)
                    {
                        re.results.Add(i.Key, new editor.cfg.blueprint.ConstFloat() { value = (i.Value as ValueInput<float>).defaultValue });
                    }
                    else if (i.Value is ValueInput<long>)
                    {
                        re.results.Add(i.Key, new editor.cfg.blueprint.ConstLong() { value = (i.Value as ValueInput<long>).defaultValue });
                    }
                    else if (i.Value is ValueInput<bool>)
                    {
                        re.results.Add(i.Key, new editor.cfg.blueprint.ConstBool() { value = (i.Value as ValueInput<bool>).defaultValue });
                    }
                    else if (i.Value is ValueInput<Vector2>)
                    {
                        Vector2 v = (i.Value as ValueInput<Vector2>).defaultValue;
                        re.results.Add(i.Key, new editor.cfg.blueprint.ConstVector2() { value = new editor.cfg.map.Vector2() { x = v.x, y = v.y } });
                    }
                    else if (i.Value is ValueInput<Vector3>)
                    {
                        Vector3 v = (i.Value as ValueInput<Vector3>).defaultValue;
                        re.results.Add(i.Key, new editor.cfg.blueprint.ConstVector3() { value = new editor.cfg.map.Vector3() { x = v.x, y = v.y, z = v.z} });
                    }
                    else
                    {
                        Debug.Assert(false, "Result_export param dont support: " + i.Value.type);
                    }
                }
                else
                {
                    re.results.Add(i.Key, new editor.cfg.blueprint.OutputPin() { nodeId = p.parent.id, pinName = p.name });
                }
            }

            return re;
        }
    }
}
